<script setup lang="ts">
import { useColumns } from "./columns";
import { TableProBar } from "@/components/ReTable";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import MenuDialog, {
  initMenuDialog,
} from "@/views/system/menu/component/menuDialog.vue";

defineOptions({
  name: "Dept",
});

const {
  columns,
  dataList,
  loading,
  tableRef,
  handleDelete,
  reloadChildren,
  handleSelectionChange,
  onSearch,
  loadChildren,
} = useColumns();

const { openEdit, openAdd } = initMenuDialog();
</script>

<template>
  <div class="main">
    <TableProBar
      title="菜单列表"
      :loading="loading"
      :tableRef="tableRef"
      :dataList="dataList"
      @refresh="onSearch"
    >
      <template #buttons>
        <el-button
          type="primary"
          @click="openAdd"
          :icon="useRenderIcon('ri:add-circle-line')"
        >
          新增菜单
        </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table
          ref="tableRef"
          border
          align-whole="center"
          row-key="id"
          showOverflowTooltip
          table-layout="auto"
          :size="size"
          :data="dataList"
          :columns="columns"
          :checkList="checkList"
          lazy
          :load="loadChildren"
          :tree-props="{ children: 'children', hasChildren: 'isLeaf' }"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)',
          }"
          @selection-change="handleSelectionChange"
        >
          <template #operation="{ row }">
            <Auth value="MENU_EDIT">
              <el-button
                class="reset-margin"
                link
                type="primary"
                :size="size"
                @click="openEdit(row)"
                :icon="useRenderIcon('ep:edit-pen')"
              >
                修改
              </el-button>
            </Auth>
            <Auth value="MENU_DELETE">
              <el-popconfirm title="是否确认删除?" @confirm="handleDelete(row)">
                <template #reference>
                  <el-button
                    class="reset-margin"
                    link
                    type="primary"
                    :size="size"
                    :icon="useRenderIcon('ep:delete')"
                  >
                    删除
                  </el-button>
                </template>
              </el-popconfirm>
            </Auth>
          </template>
        </pure-table>
      </template>
    </TableProBar>
    <MenuDialog @reload="reloadChildren" />
  </div>
</template>
